package com.iamteer.day14;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class ShowIpTag extends SimpleTagSupport {
/*	private JspContext context;
	
	@Override
	public void setJspContext(JspContext pc) {
		this.context = pc;
	}*/
	
	@Override
	public void doTag() throws JspException, IOException {
		//向浏览器输入 IP 地址
//		PageContext pageContext = (PageContext) context;
		PageContext pageContext = (PageContext) this.getJspContext();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		
		String ip = request.getRemoteHost();
		JspWriter out = pageContext.getOut();
		out.write("自定义标签输出 IP：" + ip);
	}
}
